﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Linq;

namespace TheOliver.Controls
{
    public class PageTurnerControl : Panel
    {
        public PageTurnerControl()
        {
            this.Loaded += (s, e) =>
                {
                    CheckForError();
                };
        }

        private void CheckForError()
        {
            foreach (var page in this.Children)
            {
                if (!(page is PageTurnerPage))
                {
                    this.Children.Clear();
                    TextBlock tb = new TextBlock();
                    tb.Foreground = new SolidColorBrush(Colors.Red);
                    tb.Text = "Only elements of type " + typeof(PageTurnerPage).Name + " allowed";
                    tb.FontSize = 20;
                    this.Children.Add(tb);
                    break;
                }
            }
        }

        protected override Size  ArrangeOverride(Size finalSize)
 	    {
            var pages = this.Children.OfType<PageTurnerPage>();
            foreach (var page in pages)
            {
                page.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
                page.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            }
            return base.ArrangeOverride(finalSize);
        }
    }
}
